﻿function doInit() {
	try {
		var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");

		if (prefs.prefHasUserValue("extensions.growlgntp-songbird.trackchange-title"))				
			document.getElementById("growl-title").value = prefs.getCharPref("extensions.growlgntp-songbird.trackchange-title");
		if (prefs.prefHasUserValue("extensions.growlgntp-songbird.trackchange-message"))				
			document.getElementById("growl-label").value = prefs.getCharPref("extensions.growlgntp-songbird.trackchange-message");
		
		if (prefs.getBoolPref("extensions.growlgntp-songbird.resume-customized")) {
			document.getElementById("growl-resumecustomized").checked = true;
		}
		else {
			document.getElementById("growl-resumetitle").disabled = true;
			document.getElementById("growl-resumelabel").disabled = true;
		}
		if (prefs.prefHasUserValue("extensions.growlgntp-songbird.resume-title"))				
			document.getElementById("growl-resumetitle").value = prefs.getCharPref("extensions.growlgntp-songbird.resume-title");
		if (prefs.prefHasUserValue("extensions.growlgntp-songbird.resume-message"))				
			document.getElementById("growl-resumelabel").value = prefs.getCharPref("extensions.growlgntp-songbird.resume-message");
	}
	catch (err) {
		alert("Error\n"+ err);
	}
}

function doOK() {
	try {
		var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");

		prefs.setCharPref("extensions.growlgntp-songbird.trackchange-title", document.getElementById("growl-title").value);
		prefs.setCharPref("extensions.growlgntp-songbird.trackchange-message", document.getElementById("growl-label").value);
		
		prefs.setBoolPref("extensions.growlgntp-songbird.resume-customized", document.getElementById("growl-resumecustomized").checked);
		prefs.setCharPref("extensions.growlgntp-songbird.resume-title", document.getElementById("growl-resumetitle").value);
		prefs.setCharPref("extensions.growlgntp-songbird.resume-message", document.getElementById("growl-resumelabel").value);
	}
	catch (err) {
		alert("Error\n"+ err);
	}
	return true;	
}

function onResumeCustomizeClick() {
	var title = document.getElementById("growl-resumetitle");
	var label = document.getElementById("growl-resumelabel");
	
	if (document.getElementById("growl-resumecustomized").checked) {
		title.disabled = true;
		label.disabled = true;
	}
	else {
		title.disabled = false;
		label.disabled = false;
	}
}